<template>
  <!-- 关注和不关注 按钮 封账成组件 -->
  <van-button
    v-if="value"
    class="follow-btn"
    type="default"
    round
    :loading="loading"
    size="small"
    icon="plus"
    @click="isFollow"
    >已关注</van-button
  >
  <van-button
    v-else
    class="follow-btn"
    type="info"
    :loading="loading"
    color="#3296fa"
    round
    size="small"
    icon="plus"
    @click="isFollow"
    >关注</van-button
  >
</template>

<script>
import { addFollow, delFollow } from "@/api/user.js";

export default {
  data() {
    return {
      loading: false,
    };
  },
  props: {
    value: {
      type: [Boolean],
      required: true,
    },
    aut_id: {
      type: [String, Number],
      required: true,
    },
  },
  methods: {
    isFollow() {},
    // 关注 取消关注
    async isFollow() {
      this.loading = true;
      try {
        if (this.value) {
          const { data } = await delFollow(this.aut_id);
          this.loading = false;
        } else {
          const { data } = await addFollow(this.aut_id);
          this.loading = false;
        }
        // console.log(this.article.is_followed);
        this.$emit("input", !this.value);
        // this.article.is_followed = !this.article.is_followed;
      } catch (err) {
        this.loading = false;
        console.log(err);
        if (err.response && err.response.status === 400) {
          this.$toast("不可以关注自己!");
        } else if (err.response && err.response.status === 401) {
          this.$toast("用户登录信息获取失败，请重新登录!");
        } else {
          this.$toast("操作失败，请重试!");
        }
      }
    },
  },
};
</script>

<style>
</style>